

import 'package:flutter/material.dart';
import 'package:moonplay/common/app_common.dart';
import 'package:moonplay/pages/views/index/video_list_page.dart';

class OneIndexPage extends StatefulWidget {
  @override
  _OneIndexPageState createState() => _OneIndexPageState();
}

class _OneIndexPageState extends State<OneIndexPage> with SingleTickerProviderStateMixin {
  List<String> _tabs = ['电影', '电视剧', '综艺', '动漫'];
  TabController _tabController;
  int tabIndex = 0;

  @override
  void initState() {
    super.initState();

    _tabController = TabController(vsync: this, initialIndex: 0, length: 4)
    ..addListener(() {
      setState(() {
        tabIndex = _tabController.index;
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: _tabs.length,
      child: Scaffold(
        appBar: CustomAppbar(
          title: _widgetTitle(),
          navigationBarBackgroundColor: Theme.of(context).primaryColorLight,
          leadingWidget: Container(),
          trailingWidget: rightBarButtonItemsWidget(),
        ),
        body: TabBarView(
          controller: _tabController,
          children: [
            VideoListPage(type: 1),
            VideoListPage(type: 2),
            VideoListPage(type: 3),
            VideoListPage(type: 4),
          ],
        ),
      )
    );
  }

  Widget rightBarButtonItemsWidget(){
    return GestureDetector(
      behavior: HitTestBehavior.translucent,
      onTap: (){
        
      },
      child: Container(
        width: ScreenUtil().getWidthPx(100),
        height: ScreenUtil().getWidthPx(100),
        alignment: Alignment.center,
        color: Colors.transparent,
        child: Icon(IconData(0xe650, fontFamily: Constants.IconFontFamily),color: Colors.white, size: 22),
      ),
    );
  }

  Widget _widgetTitle(){
    return Container(
      padding: EdgeInsets.only(right: 00),
      child: TabBar(
        isScrollable: true,
        controller: _tabController,
        indicatorWeight: 2.0,
        indicatorPadding: EdgeInsets.all(4),
        labelPadding: EdgeInsets.only(left: 16.0, right: 16.0),
        indicator: CommonUnderlineTabIndicator(borderSide:  BorderSide(width: 3.0), lineColor: Colors.blue),
        indicatorSize: TabBarIndicatorSize.label,
        indicatorColor: Color(0xff4fe6c0),
        tabs: _tabs.map((val) =>
          new Tab(
            text: val,
          )).toList(),
      ),
    );
  }
}
